package android.labis.actividades;

import android.app.ListActivity;
import android.content.Intent;
import android.labis.R;
import android.labis.aplicacion;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class AlumnosTab extends ListActivity implements OnItemClickListener  {
	private aplicacion globales;
	private String[] alumnos = new String[] {
		    "pepe", "juan"
		  };
	private String[] ids = new String[] {
			"1","2"
			
	};
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.alumnos);
		globales = (aplicacion) getApplication();
		
		try {
			String[] result = globales.getConexion().GetParticipantes(globales.getIdactividad());
	    	String rest = ""; 
	    	ids = new String[result.length / 2];
	    	alumnos = new String[result.length / 2];
	    	for (int i = 0; i < result.length; i+=2) {
	    		rest += "Id: [" + result[i] + "]\nCurso: [" + result[i+1] + "]\n";
	    		ids[i/2] = result[i];
	    		alumnos[i/2] = result[i+1];
	    	}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, alumnos));

		  ListView lv = getListView();
		  lv.setTextFilterEnabled(true);

		  lv.setOnItemClickListener(this);
		
		
	}
	
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		globales.setIdalumno(ids[position]);
		  globales.setNombrealumno(alumnos[position]);
		  
		  
		  
		  
	      Toast.makeText(getApplicationContext(), getString(R.string.accesing_to)+ " " + getString(R.string.student) + ": " + alumnos[position],
		          Toast.LENGTH_SHORT).show();
		
		
		Intent intent = new Intent(this, NotaTab.class);  
		startActivity(intent);
	
	}
}
